<template>
  <el-container class="home-container">
    <el-header>
      <div>
        <img src="../assets/logo.jpg" alt="">
        <span>电商后台管理系统</span>
      </div>
      <el-button type="info" @click="logOut">退出登录</el-button>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu background-color="#333744" text-color="#fff" active-text-color="#409EFF" :unique-opened="true"
          :default-active="homeData.activeIndex" router>
          <!--一级导航-->
          <el-submenu :index="item.id+'' " v-for="item in homeData.menuList" :key="item.id">
            <template #title>
              <i :class="homeData.iconsObj[item.id]"></i>
              <span>&nbsp;&nbsp;{{ item.authName }}</span>
            </template>
            <!--二级导航-->
            <el-menu-item :index="'/' + secItem.path" v-for="secItem in item.children" :key="secItem.id">
              <template #title>
                <i class="el-icon-menu"></i>
                <span>{{secItem.authName}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { reactive, getCurrentInstance, ref, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import CompositionHandle from "../composition/home/index.js";
export default {
  setup(props, context) {
    const { ctx } = getCurrentInstance();
    const router = useRouter();
    const route = useRoute();
    let { homeData, logOutHandle, getList } = CompositionHandle;
    const initMenuList = () => {
      getList(ctx);
    };
    const logOut = () => {
      logOutHandle(router);
    };
    initMenuList();
    homeData.activeIndex = route.path;
    watch(() => route.path,(value, preValue) => {
        homeData.activeIndex = value;
      });
    return {
      logOut,
      initMenuList,
      homeData
    };
  }
};
</script>

<style lang="less" scoped>
.home-container {
  height: 100%;

  .el-header {
    background-color: #373d41;
    display: flex;
    justify-content: space-between;
    padding-left: 0;
    align-items: center;
    color: #fff;
    font-size: 20px;

    img {
      width: 70px;
    }

    > div {
      display: flex;
      align-items: center;

      span {
        margin-left: 15px;
      }
    }
  }

  .el-aside {
    background-color: #333744;
    .el-menu {
      border-right: none;
    }
  }

  .el-main {
    background-color: #eaedf1;
  }
}
</style>